function createApp() {
    const queue = []
    const next = (resolve) => {
        resolve()
    }
	return {
		use(fn) {
            queue.push(fn)
        },
		run() {
            let fn = queue.shift()
            new Promise((resolve, reject) => {
                fn.call(null, next.bind(null, resolve))
            }).then(queue.length && this.run())
        },
	};
}

const app = createApp();
app.use((next) => {
	setTimeout(function() {
		next();
	});
	console.log(new Date(), '1');
});

app.use((next) => {
	console.log(new Date(), '2');
	next();
});

app.use((next) => {
	console.log(new Date(), '3');
	next();
});

app.run();
